using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YouVisio.Silverlight.TextDiff;

namespace YouVisio.Silverlight.TextDiffTests
{
    [TestClass]
    public class DiffPartsList_Tests : BaseTestClass
    {
        [TestMethod]
        public void Can_Add_And_Iterate_Elements_Case_1()
        {
            var list = new DiffPartsList
                           {
                               Operation.Equal, 
                               Operation.Insert, 
                               Operation.Delete, 
                               Operation.Change
                           };

            Assert.AreEqual(4, list.Count);

            var checkList = list.ToList();

            Assert.AreEqual(4, checkList.Count);
            Assert.AreEqual(Operation.Equal, checkList[0]);
            Assert.AreEqual(Operation.Insert, checkList[1]);
            Assert.AreEqual(Operation.Delete, checkList[2]);
            Assert.AreEqual(Operation.Change, checkList[3]);
        }

        [TestMethod]
        public void Can_Add_And_Iterate_Elements_Case_2()
        {
            var list = new DiffPartsList
                           {
                               Operation.Equal,
                               Operation.Equal,
                               Operation.Insert,
                               Operation.Delete,
                               Operation.Delete,
                               Operation.Change
                           };

            Assert.AreEqual(6, list.Count);

            var checkList = list.ToList();

            Assert.AreEqual(6, checkList.Count);
            Assert.AreEqual(Operation.Equal, checkList[0]);
            Assert.AreEqual(Operation.Equal, checkList[1]);
            Assert.AreEqual(Operation.Insert, checkList[2]);
            Assert.AreEqual(Operation.Delete, checkList[3]);
            Assert.AreEqual(Operation.Delete, checkList[4]);
            Assert.AreEqual(Operation.Change, checkList[5]);
        }

        [TestMethod]
        public void Can_Add_And_Iterate_Elements_Case_3()
        {
            var list = new DiffPartsList
                           {
                               Operation.Delete, 
                               Operation.Delete, 
                               Operation.Delete
                           };

            Assert.AreEqual(3, list.Count);

            var checkList = list.ToList();

            Assert.AreEqual(3, checkList.Count);
            Assert.AreEqual(Operation.Delete, checkList[0]);
            Assert.AreEqual(Operation.Delete, checkList[1]);
            Assert.AreEqual(Operation.Delete, checkList[2]);
        }



        [TestMethod]
        public void Can_Identify_Empty_List()
        {
            var list = new DiffPartsList();

            Assert.AreEqual(0, list.Count);

            var checkList = list.ToList();

            Assert.AreEqual(0, checkList.Count);
        }

        [TestMethod]
        public void Can_Clear_List()
        {
            var list = new DiffPartsList
                           {
                               Operation.Change, 
                               Operation.Delete
                           };

            Assert.AreEqual(2, list.Count);

            list.Clear();

            Assert.AreEqual(0, list.Count);

            var checkList = list.ToList();

            Assert.AreEqual(0, checkList.Count);

        }
    }
}